package net.tycmc.cty.ctyms.timejob.iems.dao;
import java.util.List;
import java.util.Map;




import net.tycmc.bulb.common.dao.IBaseDAO;
import net.tycmc.bulb.common.util.StringUtil;
import net.tycmc.bulb.dbutil.global.GlobalDBVar;
import net.tycmc.cty.ctyms.timejob.common.MyConnectDSDAO;

public class MtnProgarmDao {
	private IBaseDAO baseDAO;

	/**
	 * @return the baseDAO
	 */
	public IBaseDAO getBaseDAO() {
		return baseDAO;
	}

	/**
	 * @param baseDAO the baseDAO to set
	 */
	public void setBaseDAO(IBaseDAO baseDAO) {
		this.baseDAO = baseDAO;
	}
	
	/**
	 * 查询保养提醒设备集合
	 */
	public List<Map<String,Object>> getMtnVehicleList(){
		StringBuffer sbf = new StringBuffer("");

		sbf.append(" select * from (");
		sbf.append(" select 	vcl.vehicleid,vcl.VehicleNumber,mtp.MtnTp_RulesType,MtnAS_Type,mtp.MtnTp_Name,mtp.MtnTp_SpaceKM,MtnTp_FloatKM ,VehicleRumKmID,");
		sbf.append(" mas.mtnas_lastTime,mas.mtnas_LastKM,MtnAS_TpId,MtnAS_PgId,mtnas_remark, mtnas_remindkm,");
		sbf.append(" isnull(case when vcl.VehicleRumKmID=1 then mel.MsgESL_tRunKmExact ");
		sbf.append(" 	 when vcl.VehicleRumKmID=2 then mel.MsgESL_tRunKmExact_ECM ");
		sbf.append(" 	 when vcl.VehicleRumKmID=3 then mel.MsgESL_tRunKm_ECM ");
		sbf.append(" 	 when vcl.VehicleRumKmID=4 then mel.MsgESL_tRunKm_ECU ");
		sbf.append(" 	 when vcl.VehicleRumKmID=5 then mel.MsgESL_TMileage else msgesl_trunkmexact ");
		sbf.append(" end,0) nowKm,MtnAS_Next");
		sbf.append(" from MtnProgram_AlertStat mas ");
		sbf.append(" inner join ");
		sbf.append(" v_vehicleinfo vcl on mas.mtnas_vclId = vcl.VehicleID");
		sbf.append(" left join MtnProgram_Type mtp on mas.MtnAS_TpId = mtp.MtnTp_Id");
		sbf.append(" left join ");
		sbf.append(" CTY_Egn_B.dbo.msg_equipmentstate_last mel on vcl.VehicleID = mel.MsgESL_Vcl_ID )aa");
		sbf.append(" where  isnull(MtnAS_Type,0) < 3 or nowKm>MtnAS_Next ");

		List<Map<String,Object>> list = this.getBaseDAO().execQuery(sbf.toString(), new Object[]{});
		return list;
	}
	
	
	public List<Map<String,Object>> getMtnLinkManByParam(Map<String,Object> param ){
		String vehicleId = param.get("vehicleId")+"";
		StringBuffer strSQL = new StringBuffer();
		strSQL.append(" select MtnLk_Id,MtnLk_VclId,MtnLk_Name,MtnLk_Phone,MtnLk_Email,MtnLk_Type,MtnLk_RemindWay from MtnProgram_LinkMan where MtnLk_VclId = ?");
		List<Map<String,Object>> list = this.getBaseDAO().execQuery(strSQL.toString(), new Object[]{vehicleId});
		return list; 
	}
	
	
	public int toQuerySql(String sql){
		int i= new MyConnectDSDAO() .execInsert(sql.toString(), new Object[]{});
		return i;
	}
	
	public List<Map<String,Object>> getLastMtnEt(Map<String, Object> params) {
		
		String vehicleId = params.get("vehicleId")+"";
		String mtnastpid = params.get("mtnastpid")+"";
		
		StringBuffer strBuf = new StringBuffer();
		
		strBuf.append("select top 1 MtnEt_Id,MtnEt_TyId,MtnEt_NextRemark from MtnEnter_Info where MtnEt_VclId = '"+vehicleId+"' and MtnEt_TyId='"+mtnastpid+"' order by MtnEt_MtnTime desc");

		List<Map<String,Object>> list = this.getBaseDAO().execQuery(strBuf.toString(), new Object[]{});
		return list; 
		
	}
	
}
